﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Openfree.Framework;

public partial class PMSWeb_ImportData : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnImport_Click(object sender, EventArgs e)
    {
        DataSet ds = BaseAccess.GetDataSet(base.Connection, "select * from PMS_Customer_Import_Temp", "PMS_Customer_Import_Temp");

        foreach(DataRow row in ds.Tables[0].Rows)
        {
            int tmpInt = 0;
            if (row["LightNo"].ToString() == "")
            {
                row["LightNo"] = "0";
            }
            else if(!Int32.TryParse(row["LightNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["LightNo"].ToString()  + "\r\n";
                row["LightNo"] = "0";
            }

            if (row["PhoneNo"].ToString() == "")
            {
                row["PhoneNo"] = "0";
            }
            else if (!Int32.TryParse(row["PhoneNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["PhoneNo"].ToString() + "\r\n";
                row["PhoneNo"] = "0";

            }

            if (row["ComputerNo"].ToString() == "")
            {
                row["ComputerNo"] = "0";
            }
            else if (!Int32.TryParse(row["ComputerNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["ComputerNo"].ToString() + "\r\n";
                row["ComputerNo"] = "0";
            }

            if (row["TVNo"].ToString() == "")
            {
                row["TVNo"] = "0";
            }
            else if (!Int32.TryParse(row["TVNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["TVNo"].ToString() + "\r\n";
                row["TVNo"] = "0";
            }

            if (row["CopierNo"].ToString() == "")
            {
                row["CopierNo"] = "0";
            }
            else if (!Int32.TryParse(row["CopierNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["CopierNo"].ToString() + "\r\n";
                row["CopierNo"] = "0";
            }

            if (row["AirNo"].ToString() == "")
            {
                row["AirNo"] = "0";
            }
            else if (!Int32.TryParse(row["AirNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["AirNo"].ToString() + "\r\n";
                row["AirNo"] = "0";
            }

            if (row["Extension"].ToString() == "")
            {
                row["Extension"] = "0";
            }
            else if (!Int32.TryParse(row["Extension"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["Extension"].ToString() + "\r\n";
                row["Extension"] = "0";
            }

            if (row["RadiatorNo"].ToString() == "")
            {
                row["RadiatorNo"] = "0";
            }
            else if (!Int32.TryParse(row["RadiatorNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["RadiatorNo"].ToString() + "\r\n";
                row["RadiatorNo"] = "0";
            }

            if (row["ThermostatNo"].ToString() == "")
            {
                row["ThermostatNo"] = "0";
            }
            else if (!Int32.TryParse(row["ThermostatNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["ThermostatNo"].ToString() + "\r\n";
                row["ThermostatNo"] = "0";
            }

            if (row["DoorNo"].ToString() == "")
            {
                row["DoorNo"] = "0";
            }
            else if (!Int32.TryParse(row["DoorNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["DoorNo"].ToString() + "\r\n";
                row["DoorNo"] = "0";
            }

            if (row["WindowsNo"].ToString() == "")
            {
                row["WindowsNo"] = "0";
            }
            else if (!Int32.TryParse(row["WindowsNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["WindowsNo"].ToString() + "\r\n";
                row["WindowsNo"] = "0";
            }


            if (row["HeadNo"].ToString() == "")
            {
                row["HeadNo"] = "0";
            }
            else if (!Int32.TryParse(row["HeadNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["HeadNo"].ToString() + "\r\n";
                row["HeadNo"] = "0";
            }


            if (row["SmokeNo"].ToString() == "")
            {
                row["SmokeNo"] = "0";
            }
            else if (!Int32.TryParse(row["SmokeNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["SmokeNo"].ToString() + "\r\n";
                row["SmokeNo"] = "0";
            }

            if (row["SwitchNo"].ToString() == "")
            {
                row["SwitchNo"] = "0";
            }
            else if (!Int32.TryParse(row["SwitchNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["SwitchNo"].ToString() + "\r\n";
                row["SwitchNo"] = "0";
            }

            if (row["PowerNo"].ToString() == "")
            {
                row["PowerNo"] = "0";
            }
            else if (!Int32.TryParse(row["PowerNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["PowerNo"].ToString() + "\r\n";
                row["PowerNo"] = "0";
            }

            if (row["PhoneJackNo"].ToString() == "")
            {
                row["PhoneJackNo"] = "0";
            }
            else if (!Int32.TryParse(row["PhoneJackNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["PhoneJackNo"].ToString() + "\r\n";
                row["PhoneJackNo"] = "0";
            }

            if (row["ToiletNo"].ToString() == "")
            {
                row["ToiletNo"] = "0";
            }
            else if (!Int32.TryParse(row["ToiletNo"].ToString(), out tmpInt))
            {
                row["Remark"] = row["Remark"].ToString() + row["ToiletNo"].ToString() + "\r\n";
                row["ToiletNo"] = "0";
            }

            float tmpFloat = 0;
            if (row["Area"].ToString().Trim() == "")
            {
                row["Area"] = "0";
            }
            else if (!float.TryParse(row["Area"].ToString(), out tmpFloat))
            {
                row["Remark"] = row["Remark"].ToString() + row["Area"].ToString() + "\r\n";
                row["Area"] = "0";
            }
            //dsNew.Tables[0].Rows.Add(row.ItemArray);
        }

        BaseAccess.UpdateDataSet(base.Connection, "PMS_Customer_Import_Temp", ds);



        gridView.DataSource = ds.Tables[0];
        gridView.DataBind();
        
    }
}
